<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包实现模块化</title>
</head>

<body>
    <script>
        const obj = (function () {
            let count = 0
            return {
                increase: function () {
                    return ++count
                },
                decrease: function () {
                    return --count
                }
            }
        })()

        console.log(obj.increase())
        console.log(obj.decrease())
        // 没有途径访问到 count，但是 count 一直留在内存中
        console.log(obj.count)

    </script>
</body>

</html>